package tw.com.hitevision.whiteboard.android.widgets.MeasurementTools;

import android.content.Context;
import android.graphics.Paint;
import android.graphics.PointF;
import android.view.MotionEvent;
import android.view.View;

public abstract class BasicRuler extends View {
    public BasicRuler(Context context) {
        super(context);
    }

    public abstract void setDrawingLineWidth(float width);

    public abstract boolean rulerOnTouch(View v, MotionEvent event, boolean canDraw);

    public abstract void loadMeasurementToolRecord(MeasurementToolRecord record);

    public abstract MeasurementToolRecord createMeasurementToolRecord();

    String name;

    public String getName() {
        return name;
    }

    PointF getUnitVector (float u, float v) {
        PointF p = new PointF(u, v);
        float d = p.length();
        p.x /= d;
        p.y /= d;
        return p;
    }

    PointF getNormalVectorCCW(PointF f) {
        PointF p = new PointF();
        p.x = -f.y;
        p.y = f.x;
        return p;
    }

    float getDegreeStopOffset(float oldDegree, float skip, float unit) {
        oldDegree = (oldDegree + 360) % 360;
        float degree = oldDegree;
        float m = degree % unit;
        float absM = Math.abs(m);
        if (absM < skip && absM > 0f) {
            degree = Math.round(degree - m);
        } else if (absM < unit && absM > unit - skip) {
            degree = Math.round(degree + (unit - absM));
        }

        return degree - oldDegree;
    }

    Paint initStrokePaint() {
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeCap(Paint.Cap.ROUND);
        paint.setStrokeJoin(Paint.Join.ROUND);

        return paint;
    }

}
